

# 1、Counter是一个计数器，它可以帮助我们针对某项数据进行计数。比如它可以用来计算每个 人喜欢多少种颜色:

from collections import Counter

colours = (
    ('Yasoob', 'Yellow'),
    ('Ali', 'Blue'),
    ('Arham', 'Green'),
    ('Ali', 'Black'),
    ('Yasoob', 'Red'),
    ('Ahmed', 'Silver'),
)

favs = Counter(name for name, colour in colours)

print(favs)
# Counter({'Yasoob': 2, 'Ali': 2, 'Arham': 1, 'Ahmed': 1})

# 2、统计一个文件
with open('file/file1.txt', "r", encoding="utf-8") as f:
    line_count = Counter(f)
print(line_count)